package com.bwei.mypaot.home;

import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.widget.TextView;

import com.bwei.mypaot.R;
import com.bwei.mypaot.base.activity.BaseActivity;

/**
 * Created by Administrator on 2017/2/28.
 */

public class ActionBar extends BaseActivity {

    private FloatingActionButton ac;
    boolean flag;
    private TextView cloud;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.action_activity);
        initHeader();
        initWidget();
        setWidgetState();
    }

    @Override
    public void initHeader() {

    }

    @Override
    public void initWidget() {
        ac = (FloatingActionButton) findViewById(R.id.ac);
        cloud = (TextView) findViewById(R.id.cloud);

    }

    @Override
    public void setWidgetState() {
        ac.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!flag){
                   openMenu(v);
                }else{
                  closeMenu(v);
                }

            }
        });

    }
    public void openMenu(View view){
        ObjectAnimator animator= ObjectAnimator.ofFloat(view,"rotation",0,-155,-135);
        animator.setDuration(500);
        animator.start();
        cloud.setVisibility(View.VISIBLE);
        AlphaAnimation alphaAnimation= new AlphaAnimation(0,1.0f);
        alphaAnimation.setDuration(500);
        alphaAnimation.setFillAfter(true);
        cloud.startAnimation(alphaAnimation);
        flag=true;

    }
    public void closeMenu(View view){
        ObjectAnimator animator= ObjectAnimator.ofFloat(view,"rotation",-135,20,0);
        animator.setDuration(500);
        animator.start();
        AlphaAnimation alphaAnimation= new AlphaAnimation(1.0F,0);
        alphaAnimation.setDuration(500);
        alphaAnimation.setFillAfter(true);
        cloud.startAnimation(alphaAnimation);
        cloud.setVisibility(View.GONE);
        flag=false;

    }


    @Override
    public void onClick(View view) {
        super.onClick(view);


    }
}
